import os
import cv2


def SaveVisImg(vis_img, pc_name_set, output_path):
    one_pc_name = pc_name_set  # [list(pc_name_set)[0]]

    pure_name = one_pc_name.split("/")[-1][:-4]
    output_name = os.path.join(output_path, pure_name + ".jpg")

    cv2.imwrite(output_name, vis_img)


def Pic2Video(file, video_name):
    fps = 10  # 视频每秒10帧
    size = (1600, 970)  # 需要转为视频的图片的尺寸
    fourcc = cv2.VideoWriter_fourcc(*'XVID')

    list = os.listdir(file)
    # list = sorted(list, key=lambda x: int(x[:-4]))
    list = sorted(list)
    img12 = cv2.imread(os.path.join(file, list[0]))
    size = (img12.shape[1],img12.shape[0])
    print(size)
    videoWriter = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), fps, size)

    for i in list:
        img12 = cv2.imread(os.path.join(file, i))
        img12 = cv2.resize(img12, size)
        videoWriter.write(img12)
    videoWriter.release()
if __name__ == '__main__':

    Pic2Video('/media/zhl/00030FC90009D3A0/lidar/data36_2020_05_12/image/1','./test.mp4')
